// @ts-ignore
/* eslint-disable */
import {request} from 'umi';
import {GeographicItemType} from '@/pages/Account/Settings/data';
import {ErrorShowType} from "@@/plugin-request/request";

/** 获取当前的用户 POST /v2/enterprise/account/info */
export async function currentUser(options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
  }>('/v2/enterprise/account/info', {
    method: 'POST',
    showType: ErrorShowType.SILENT,
    ...(options || {}),
  });
}

/** 退出登录接口 POST /v2/enterprise/logout */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/v2/enterprise/logout', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /v2/enterprise/login */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.Result<string>>('/v2/enterprise/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    showType: ErrorShowType.SILENT,
    // skipErrorHandler: false,
    ...(options || {}),
  });
}


export async function scanLogin(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.Result<string>>('/v2/enterprise/scan-code', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    showType: ErrorShowType.SILENT,
    // skipErrorHandler: false,
    ...(options || {}),
  });
}

export async function scanResult(key: String) {
  return request<API.Result<string>>(`/v2/enterprise/scan-result/${key}`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    showType: ErrorShowType.SILENT,
  });
}

export async function doRegister(params: API.RegisterParams) {
  return request<API.Result<API.RegisterResult>>('/v2/enterprise/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

export async function doCaptcha(phone: string) {
  return request<API.Result<string>>('/v2/enterprise/register/captcha/' + phone, {
    method: 'POST',
  });
}

export async function doForgetCaptcha(phone: string) {
  return request<API.Result<string>>('/v2/enterprise/find-captcha/' + phone, {
    method: 'POST',
  });
}

export async function doFindPassword(params: API.RegisterParams) {
  return request<API.Result<API.RegisterResult>>('/v2/enterprise/find-password', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

export async function doFindAccount(params: API.RegisterParams) {
  return request<API.Result<API.RegisterResult>>('/v2/enterprise/find-account', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

export async function checkCompanyName(params: string): Promise<{ data: string }> {
  return request('/v2/enterprise/check/company-name', {
    method: 'POST',
    data: params,
  });
}

export async function checkCreditCode(params: String) {
  return request<API.Result<string>>('/v2/enterprise/check/credit-code', {
    method: 'POST',
    data: params,
  });
}

export async function loadProvince(): Promise<{ data: GeographicItemType[] }> {
  return request('/v2/geographic/province');
}

export async function loadCity(province: string): Promise<{ data: GeographicItemType[] }> {
  return request(`/v2/geographic/city/${province}`);
}

export async function loadArea(city: string): Promise<{ data: GeographicItemType[] }> {
  return request(`/v2/geographic/area/${city}`);
}

export async function loadCategory() {
  return request<API.Result<API.CascaderItem>>('/v2/enterprise/category/tree', {
    method: 'POST',
  });
}

export async function areaTree() {
  return request<API.Result<API.AreaItem>>('/v2/area/tree', {
    method: 'POST',
  });
}

/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
  return request<API.NoticeIconList>('/api/notices', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /api/rule */
export async function rule(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<API.RuleList>('/api/rule', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'PUT',
    ...(options || {}),
  });
}

/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/rule', {
    method: 'DELETE',
    ...(options || {}),
  });
}


/** 登录接口 POST /v2/enterprise/login */
export async function upload(data: File, options?: { [key: string]: any }) {
  let filedata = new FormData();
  filedata.append('file', data);
  return request<API.Result<API.EditorUpload>>('/v2/enterprise/editor/upload', {
    method: 'POST',
    requestType: 'form',
    headers: {
      'Content-Type': 'application/json',
    },
    data: filedata,
    showType: 0,
    // skipErrorHandler: false,
    ...(options || {}),
  });
}
